package cn.wjdiankong.levideo.utils;

import com.ss.android.common.applog.GlobalContext;

import android.content.Context;
import android.content.SharedPreferences;

public class PreferenceUtil {
	
	private final static String sp_name = "levideo_config";
	private static SharedPreferences sp = null;
	
	private static void init(){
		if(sp == null){
			sp = GlobalContext.getContext().getSharedPreferences(sp_name, Context.MODE_PRIVATE);
		}
	}
	
	public static void setValue(String key, Object objValue){
		init();
		if(objValue.getClass() == Integer.class){
			sp.edit().putInt(key, (int)objValue).commit();
		}else if(objValue.getClass() == Boolean.class){
			sp.edit().putBoolean(key, (boolean)objValue).commit();
		}else if(objValue.getClass() == Float.class){
			sp.edit().putFloat(key, (float)objValue).commit();
		}else if(objValue.getClass() == Long.class){
			sp.edit().putLong(key, (long)objValue).commit();
		}else if(objValue.getClass() == String.class){
			sp.edit().putString(key, (String)objValue).commit();
		}
	}
	
	public static Object getValue(String key, Object objValue){
		init();
		if(objValue.getClass() == Integer.class){
			return sp.getInt(key, 0);
		}else if(objValue.getClass() == Boolean.class){
			return sp.getBoolean(key, false);
		}else if(objValue.getClass() == Float.class){
			return sp.getFloat(key, 0);
		}else if(objValue.getClass() == Long.class){
			return sp.getLong(key, 0);
		}else if(objValue.getClass() == String.class){
			return sp.getString(key, "");
		}
		return null;
	}
	
}
